import mountElement from './mountElement'
import updateNodeElement from './updateNodeElement'
export default function createDomElement (virtualDOM) {
  let newDom = null

  if (virtualDOM.type === 'text') {
    newDom = document.createTextNode(virtualDOM.props.textContent)
  } else {
    newDom = document.createElement(virtualDOM.type)
    updateNodeElement(newDom, virtualDOM)
  }

  newDom._virtualDOM = virtualDOM

  virtualDOM.children.forEach(child => {
    mountElement(child, newDom)
  });

  return newDom
}